package com.shop2cn.iapi.coupon.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.getMyCouponNumBean;
import com.shop2cn.iapi.coupon.service.UserReceiveCouponCall;
import com.shop2cn.iapi.coupon.service.getMyCouponNumCall;
import com.shop2cn.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.shop2cn.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnCallService;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.utils.TestDataManager;
/**
*我的优惠券数量
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMyCouponNum{
	private static getMyCouponNumBean bean;
	private static getMyCouponNumCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("我的优惠券数量");
	}

	@Before
	public void caseUp() {
		bean=new getMyCouponNumBean();
		call=new getMyCouponNumCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_001() {
		Logger.start(true,"我的优惠券数量-验证数量为1 未使用");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			bean.setBuyerId(userId);
			bean.setSellerId(sellerCreateBatchBean.getSellerId());
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(1, call.getUsableCouponNum(), "验证返回的与数据库的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_001_1() {
		Logger.start(true,"我的优惠券数量-验证我的数量为1 已过期");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
//			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
//			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
//			
//			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
//			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
//			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			bean.setBuyerId(userId);
			//bean.setSellerId(sellerCreateBatchBean.getSellerId());
			bean.setSellerId(433259);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_001_3() {
		Logger.start(true,"我的优惠券数量-验证数量为1 未使用 商家作废批次");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			CouponShop2cnMCallService.InvalidSellerBatch(sellerCreateBatchBean.getSellerId(), createCouponCall.getBatchCode());
			bean.setBuyerId(userId);
			bean.setSellerId(sellerCreateBatchBean.getSellerId());
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(1, call.getUsableCouponNum(), "验证返回的与数据库的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_001_2() {
		Logger.start(true,"我的优惠券数量-验证我的数量为1-已使用");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			CouponShop2cnMCallService.UseCoupon(userId, userReceiveCouponCall.getUserReceiveResult().getCouponCode());
			bean.setBuyerId(userId);
			bean.setSellerId(sellerCreateBatchBean.getSellerId());
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_002() {
		Logger.start(true,"我的优惠券数量-验证buyerId不存在");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			bean.setBuyerId(userId+11);
			bean.setSellerId(sellerCreateBatchBean.getSellerId());
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_003() {
		Logger.start(true,"我的优惠券数量-验证sellerId不存在");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			bean.setBuyerId(userId);
			bean.setSellerId(sellerCreateBatchBean.getSellerId()+111);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("操作成功！", call.getMessage(), "验证返回Message");
			Logger.verifyEquals("0", call.getStatusCode1(), "验证返回StatusCode");
			
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_004() {
		Logger.start(true,"我的优惠券数量-验证buyerId为空");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
		//	bean.setBuyerId(userId);
			bean.setSellerId(sellerCreateBatchBean.getSellerId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("1", call.getStatusCode1(), "验证返回StatusCode");
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMyCouponNum_005() {
		Logger.start(true,"我的优惠券数量-验证sellerId为空");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			int orderId = TestDataManager.getRandomIntNum(10);
			
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			CouponShop2cnCallService CouponShop2cnCallService = new CouponShop2cnCallService();
			
			SellerCreateBatchBean sellerCreateBatchBean = CouponShop2cnMCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall= CouponShop2cnMCallService.SellerCreateBatch(sellerCreateBatchBean);
			UserReceiveCouponCall userReceiveCouponCall = CouponShop2cnMCallService.receiveCouponInfo(createCouponCall.getBatchCode(), userId);
			
			bean.setBuyerId(userId);
			//bean.setSellerId(sellerCreateBatchBean.getSellerId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("1", call.getStatusCode1(), "验证返回StatusCode");
			Logger.verifyEquals(0, call.getUsableCouponNum(), "验证返回的与数据库的一致");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}